<template>
  <div class="app-container">
    <el-form :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      class="form-search"
      label-width="100px">
      <el-form-item :label="$t('payrollT.exchangeName')"
        prop="exchangeName">
        <el-select v-model="queryParams.exchangeId"
          filterable
          remote
          reserve-keyword
          :placeholder="$t('common.placeholderSelect')"
          :remote-method="remoteMethod"
          :loading="exhloading"
          style="width: 240px">
          <el-option v-for="item in exchangeList"
            :key="item.exchangeId"
            :label="item.exchangeName"
            :value="item.exchangeId">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item :label="$t('payrollT.subject')"
        prop="subject">
        <el-input v-model="queryParams.subject"
          :placeholder="$t('common.placeholderContent')"
          clearable
          style="width: 240px"
          maxlength="50"
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item :label="$t('payrollT.transStatus')"
        prop="transStatus">
        <el-select v-model="queryParams.transStatus"
          :placeholder="$t('common.placeholderSelect')"
          clearable
          style="width: 240px">
          <el-option v-for="dict in dict.type.trans_status"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value" />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery">{{$t('common.search')}}</el-button>
        <el-button icon="el-icon-refresh"
          size="mini"
          @click="resetQuery">{{$t('common.reset')}}</el-button>
      </el-form-item>
    </el-form>

    <div class="section-box">
      <!-- <el-row :gutter="10"
        class="mb8">
        <el-col :span="1.5">
          <el-button type="warning"
            plain
            icon="el-icon-download"
            size="mini"
            @click="handleExport">{{$t('common.export')}}</el-button>
        </el-col>
        <right-toolbar :showSearch.sync="showSearch"
          @queryTable="getList"></right-toolbar>
      </el-row> -->

      <el-table v-loading="loading"
        :data="batchList">
        <!-- <el-table-column type="selection"
        min-width="55"
        align="center" /> -->
        <el-table-column :label="$t('payrollT.subject')"
          align="center"
          prop="subject"
          min-width="160"
          show-overflow-tooltip />
        <el-table-column :label="$t('payrollT.exchangeName')"
          align="center"
          prop="exchangeName"
          min-width="160"
          show-overflow-tooltip />
        <el-table-column :label="$t('payrollT.amount')"
          align="center"
          prop="amount"
          min-width="120" />
        <el-table-column :label="$t('payrollT.transStatus')"
          align="center"
          prop="transStatus"
          :show-overflow-tooltip="true"
          min-width="140">
          <template slot-scope="scope">
            <dict-tag :options="dict.type.trans_status"
              :value="scope.row.transStatus" />
          </template>
        </el-table-column>
        <el-table-column :label="$t('payrollT.transAmount')"
          align="center"
          prop="transAmount"
          :show-overflow-tooltip="true"
          min-width="120" />
        <el-table-column :label="$t('payrollT.payeeNumber')"
          align="center"
          prop="payeeNumber"
          min-width="120"
          show-overflow-tooltip />
        <el-table-column :label="$t('payrollT.transNumber')"
          align="center"
          prop="transNumber"
          min-width="120"
          show-overflow-tooltip />
        <el-table-column :label="$t('common.createBy')"
          align="center"
          prop="createBy"
          min-width="160"
          show-overflow-tooltip />
        <el-table-column :label="$t('common.createTime')"
          align="center"
          prop="createTime"
          min-width="180">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.createTime) }}</span>
          </template>
        </el-table-column>
        <el-table-column :label="$t('common.updateBy')"
          align="center"
          prop="updateBy"
          min-width="160"
          show-overflow-tooltip />
        <el-table-column :label="$t('common.updateTime')"
          align="center"
          prop="updateTime"
          min-width="180">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.updateTime) }}</span>
          </template>
        </el-table-column>
        <el-table-column :label="$t('common.remark')"
          prop="remark"
          min-width="160"
          show-overflow-tooltip />
        <el-table-column :label="$t('common.controls')"
          align="center"
          class-name="small-padding fixed-width"
          fixed="right"
          min-width="180">
          <template slot-scope="scope">
            <el-button size="mini"
              type="text"
              icon="el-icon-view"
              @click="handleView(scope.row)">{{$t('common.view')}}</el-button>
            <el-button size="mini"
              type="text"
              icon="el-icon-view"
              @click="handleTransferDetail(scope.row)">{{$t('payrollT.transferDetail')}}</el-button>
          </template>
        </el-table-column>
      </el-table>

      <pagination v-show="total > 0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList" />
    </div>

    <!-- 查看详情 -->
    <ViewShow :title="$t('common.viewDetail')"
      :open="showView"
      :dataList="viewList"
      :isLine="true"
      :labelWidth="160"
      width="800"
      @toClose="showView = false" />
  </div>
</template>

<script>
import {
  getPayrollTransferList,
} from "@/api/transaction/payrollTransfer.js";
import {
  getExhUserList,
} from "@/api/system/exchangeUser.js";
import ViewShow from '@/views/components/viewShow.vue'

export default {
  name: "PayrollTransfer",
  dicts: ["trans_status"],
  components: { ViewShow },
  data () {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 角色表格数据
      batchList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 日期范围
      dateRange: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        exchangeId: null,
        subject: null,
        transStatus: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {},

      exchangeList: [],
      exhloading: false,
      showView: false,
      viewList: [],
    };
  },
  created () {
    this.getList();
  },
  methods: {
    // 搜索汇兑用户
    remoteMethod (query) {
      if (query !== '') {
        this.exhloading = true;
        getExhUserList({
          pageNum: 1,
          pageSize: 10,
          payType: 'payout',
          status: 1,
          exchangeName: query
        }).then(
          (response) => {
            this.exchangeList = response.rows;
            this.exhloading = false;
          }
        );
      } else {
        this.exchangeList = [];
      }
    },
    /** 查询列表 */
    getList () {
      this.loading = true;
      getPayrollTransferList(this.queryParams).then(
        (response) => {
          this.batchList = response.rows;
          this.total = response.total;
          this.loading = false;
        }
      );
    },


    // 转账明细
    handleTransferDetail (row) {
      const batchId = row.batchId;
      this.$router.push({
        path: "/transaction/payroll-transfer/transferDetail/" + batchId,
        // query: {
        //   exchangeId: row.exchangeId,
        //   subject: row.subject
        // }
      });
    },
    // 查看详情
    handleView (row) {
      this.viewList = []
      let statusList = this.dict.type.trans_status
      let viewInfo = row;
      let showData = ['subject', 'exchangeName', 'amount', 'priority', 'transType', 'transStatus', 'transStartTime', 'transEndTime',
        'transAmount', 'payeeNumber', 'transNumber']
      let commonData = ['remark', 'createBy', 'createTime', 'updateBy', 'updateTime']

      showData.forEach(item => {
        this.viewList.push({
          type: 'text',
          label: this.$t(`payrollT.${item}`) + '：',
          value: item == 'transStatus' ? statusList.filter(i => viewInfo[item] == i.value)[0].label : viewInfo[item]
        })
      })
      commonData.forEach(item => {
        this.viewList.push({
          type: 'text',
          label: this.$t(`common.${item}`) + '：',
          value: viewInfo[item]
        })
      })

      setTimeout(() => {
        this.showView = true;
      })
    },

    /** 搜索按钮操作 */
    handleQuery () {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery () {
      this.queryParams.exchangeId = null
      this.exchangeList = []
      this.resetForm("queryForm");
      this.handleQuery();
    },
  },
};
</script>
